-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: optimize updating pools #110
Conversation
@@ -80,19 +82,16 @@ async function _handleEthBlock(block: EthereumBlock): Promise<void> { | |||
} | |||
|
|||
async function updateLoans(poolId: string, blockDate: Date, shelf: string, pile: string, navFeed: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few remarks on the general architecture:
-
We usually define all the required helper functions as methods inside the corresponding services... in this case the
LoanService.ts
would be the most appropriated. -
Event and Block Handlers should never set or assign directly the properties of entities (such as pools or loans) such as:
pool.totalReserve = ...
This is reserved to Service Methods only. This guarantees that the logic can be reused and maintained easily whenever the same operation occurs as a result of calls in different blocks or event handlers.
We can address this refactoring in a dedicated ticket. I will prepare a backlog item ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue -> #111
…nfigurable chunks
amount += results.length | ||
} while (results.length === batch) | ||
amount += entities.length | ||
} while (entities.length > 0) | ||
return results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are exactly 100 entities to query, this while loop used to enter into an infinite loop. Now, we do one extra check to make sure there are no extra entities to fetch, and if not we exit the loop.
This PR updates the eth block handler to ignore closed loans and perform all pool updates asynchronously